import { http } from '@/server'
import type { HttpResponsePending, HttpResponsePromise } from '@/server/interface'
import type * as I from './interface'
import { encryptValue } from '@/utils/encryptValue'

export const resetPwd = (params: I.ResetPwdParamsType): HttpResponsePromise<any> => {
    const { old_password, new_password } = params
    const encryptedPassword = encryptValue(old_password)
    const newEncryptedPassword = encryptValue(new_password)
    return http.post('/engineer/user/reset-self-pwd', {
        ...params,
        old_password: encryptedPassword,
        new_password: newEncryptedPassword,
        confirm_password: newEncryptedPassword,
    })
}

export const updateUserInfo = (params: I.UpdateUserInfoParamsType): HttpResponsePromise<any> =>
    http.post('/engineer/user/update-self', params)

export const getCityList = (): HttpResponsePending<I.CityListType[]> => http.get('/district')

/** 获取地区列表 */
export const getDistrict = () => http.get<I.CityListType[]>('/district')
